<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
*/
!defined('IN_MUDDER') && exit('Access Denied');
class TravelerModel {
    var $db = null;
    var $tablename = 'travelers';

    function TravelerModel() {
        global $db,$dbpre;

        $this->db = &$db;
        $this->tablename = $dbpre.$this->tablename;
    }

    function record($uid, & $user) {
        global $timestamp;
        $this->db->query("UPDATE {$this->tablename} SET addtime='$timestamp' WHERE tuid='{$user->uid}' AND uid='$uid'");
        if($this->db->affected_rows() == 0) {
            $this->db->query("INSERT INTO {$this->tablename} (uid,tuid,tusername,addtime) VALUES('$uid','{$user->uid}','{$user->username}','$timestamp')");
        }
    }

    function & read($uid, $limit) {
        if(is_numeric($limit) && $limit>0) {
            $limit = "0, $limit";
        } elseif(is_array($limit)&&count($limit)==2) {
            $limit = $limit[0].",".$limit[1];
        } else {
            $limit = "0,10";
        }
        $result = $this->db->get_all("SELECT tuid,tusername FROM {$this->tablename} WHERE uid='{$uid}' GROUP BY tuid ORDER BY addtime DESC LIMIT $limit");
        if(empty($result)) $result = false;
        return $result;
    }
}
?>